import App from "./App";

// #ifndef VUE3
import Vue from "vue";
Vue.config.productionTip = false;

Vue.prototype.toast = (msg) => {
  uni.showToast({
    title: msg,
    duration: 2000,
    position: "bottom",
    icon: "none",
  });
};

Vue.prototype.ajax = (url, data) => {
  var temp_data = data.data;
  if (temp_data == undefined) temp_data = {};
  const res = uni.getSystemInfoSync();
  //  // console.log (res)
  // 运行在小程序中
  if (res.version) {
    // this.login();
	// http://new.dongjbao.com/
	// https://meimi.nabx.cn/
    var urls = "https://meimi.nabx.cn/phone/" + url;
  } else {
    // this.html_login()
    var urls = "/phone/" + url;
  }
  var header = {
    "Content-Type": "application/json",
    token: uni.getStorageSync("token"),
  };
  uni.request({
    url: urls,
    data: temp_data,
    method: "POST",
    header: header,
    success: (res) => {
      res = res.data;
      if (res.code == 4) {
        return uni.reLaunch({
          url: "/pages/login/login",
        });
      }
      data.success(res);
    },
    fail: () => {
      uni.stopPullDownRefresh();
      uni.showToast({
        title: "请求失败",
        duration: 2000,
        icon: "none",
      });
    },
    complete: () => {},
  });
};

/**
 * 上传图片到阿里云OSS
 */
Vue.prototype.oss_upload = (res, name, data) => {
  var imageSrc = res.tempFilePaths[0] ;
  console.log(res);
  uni.uploadFile({
    url: "https://djb.oss-cn-shanghai.aliyuncs.com/",
    filePath: imageSrc,
    fileType: "image",
    name: "file",
    formData: {
      name: imageSrc,
      key: name,
      policy:
        "eyJleHBpcmF0aW9uIjoiMjEyMC0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==",
      OSSAccessKeyId: "LTAI5tCsz94SjSBHbvFV62Kh",
      success_action_status: 200,
      signature: "q9nku6ISqYSxtg26F6XPpNK4KDs=",
    },
    success: (res) => {
      // console.log (timestamp);
      data.success(res);
    },
    fail: (res) => {
      data.fail(res);
    },
  });
  /* var imageSrc = res.tempFilePaths[0];
	uni.uploadFile({
		url: 'https://jy-shops.oss-cn-beijing.aliyuncs.com/',
		filePath: imageSrc,
		fileType: 'image',
		name: 'file',
		formData: {
			name: imageSrc,
			key: name,
			policy: 'eyJleHBpcmF0aW9uIjoiMjA0MC0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==',
			OSSAccessKeyId: 'LTAIwelz9lxYTlgS',
			success_action_status: 200,
			signature: 'eLDjkSIKRnbKgNOqZajZOBjQQzc='
		},
		success: (res) => {
			 // console.log (timestamp);
			data.success(res)
		},
		fail: (res) => {
			data.fail(res)
		},
	}); */
};

App.mpType = "app";
// // main.js
// import uView from "uviewUl";
// Vue.use(uView);


const app = new Vue({
  ...App,
});
app.$mount();
// #endif

// #ifdef VUE3
import { createSSRApp } from "vue";
export function createApp() {
  const app = createSSRApp(App);
  return {
    app,
  };
}
// #endif


// 引入 uView 组件库
import uView from 'uview-ui';
Vue.use(uView); 